// 删除未使用的导入
// import { productApi } from '@/api'

// 零食分类
const categories = [
    { id: 'snacks', name: '休闲零食', icon: 'Food' },
    { id: 'drinks', name: '饮料', icon: 'Coffee' },
    { id: 'candies', name: '糖果', icon: 'Sugar' },
    { id: 'chips', name: '薯片', icon: 'Food' }
]

// 模拟商品数据
const mockProducts = [
    {
        id: 1,
        name: '乐事薯片原味',
        price: 9.90,
        image: './333/图片/乐事薯片.jpg',
        description: '经典原味薯片，香脆可口',
        category: 'chips',
        brand: '乐事',
        manufacturer: '百事食品',
        stock: 100,
        tags: ['热销', '促销']
    },
    {
        id: 2,
        name: '可口可乐',
        price: 3.50,
        image: './333/图片/可口可乐.jpg',
        description: '经典汽水饮料',
        category: 'drinks',
        brand: '可口可乐',
        manufacturer: '可口可乐公司',
        stock: 150,
        tags: ['热销']
    },
    {
        id: 3,
        name: '旺旺雪饼',
        price: 8.90,
        image: './333/图片/旺旺雪饼.jpg',
        description: '香脆可口的米制零食',
        category: 'snacks',
        brand: '旺旺',
        manufacturer: '旺旺食品',
        stock: 80,
        tags: ['新品']
    },
    {
        id: 4,
        name: '费列罗巧克力',
        price: 58.90,
        image: './333/图片/费列罗.jpg',
        description: '精致榛子巧克力糖果',
        category: 'candies',
        brand: '费列罗',
        manufacturer: '费列罗公司',
        stock: 45,
        tags: ['进口']
    },
    {
        id: 5,
        name: '百事可乐',
        price: 3.50,
        image: './333/图片/百事可乐.jpg',
        description: '清爽解暑的碳酸饮料',
        category: 'drinks',
        brand: '百事',
        manufacturer: '百事公司',
        stock: 140,
        tags: ['促销']
    },
    {
        id: 6,
        name: '康师傅方便面',
        price: 4.50,
        image: './333/图片/康师傅方便面.jpg',
        description: '经典方便面',
        category: 'snacks',
        brand: '康师傅',
        manufacturer: '康师傅食品',
        stock: 200,
        tags: ['热销', '促销']
    }
]

const state = {
    products: [],
    categories: categories,
    currentCategory: ''
}

const mutations = {
    SET_PRODUCTS(state, products) {
        state.products = products
    },
    SET_CURRENT_CATEGORY(state, category) {
        state.currentCategory = category
    }
}

const actions = {
    async getProducts({ commit, state }) {
        return new Promise((resolve) => {
            setTimeout(() => {
                let filteredProducts = [...mockProducts]
                if (state.currentCategory) {
                    filteredProducts = mockProducts.filter(p => p.category === state.currentCategory)
                }
                commit('SET_PRODUCTS', filteredProducts)
                resolve(filteredProducts)
            }, 100)
        })
    },

    async setCategory({ commit, dispatch }, category) {
        commit('SET_CURRENT_CATEGORY', category)
        return dispatch('getProducts')
    }
}

const getters = {
    productsByCategory: (state) => (category) => {
        return state.products.filter(product => product.category === category)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
} 